<?php 
  require_once("../../includes/config.php"); 
  
  $sql = 'SELECT * FROM apartments
  where owner_id = ? and (status = 2 or status = 3 or status=6 or status=1 or status = 5 or status = 7) ORDER BY apart_name';

  $binds = array();
  
  $binds['owner_id'] = $_SESSION['user_id'];

  $aprts = query($sql,$binds);
  $currentdate = date('m/d/Y', time());
  $dates = query('SELECT * FROM periods');
  foreach($dates as $date)
  {
    if(check_in_range($date['period_from'], $date['period_to'], $currentdate))
    {
      $period = $date["period_id"];
      break;
    }
  }
  
  if(!isset($period))
	{
    $period = 1;
	}
  renderWithoutHeader("Apartments/choose_apartment.php", array("aprts"=>$aprts,"period"=>$period));
?>